<template>
  <view class="loading-container" :class="{ 'loading-overlay': overlay }">
    <view class="loading-content">
      <view class="loading-spinner" :style="{ width: size + 'px', height: size + 'px' }">
        <view class="spinner-circle"></view>
      </view>
      <text v-if="text" class="loading-text">{{ text }}</text>
    </view>
  </view>
</template>

<script setup lang="ts">
interface Props {
  size?: number;
  text?: string;
  overlay?: boolean;
  color?: string;
}

withDefaults(defineProps<Props>(), {
  size: 32,
  text: '',
  overlay: false,
  color: 'var(--color-primary)'
});
</script>

<style lang="scss" scoped>
.loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  
  &.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: 9999;
  }
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
}

.loading-spinner {
  position: relative;
  display: inline-block;
}

.spinner-circle {
  width: 100%;
  height: 100%;
  border: 2px solid var(--color-divider);
  border-radius: 50%;
  border-top-color: v-bind(color);
  animation: spin 1s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: var(--color-text-secondary);
  text-align: center;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
</style>